home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1990 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appears in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * The University of Michigan not be used in advertising or
- * publicity pertaining to distribution of the software without
- * specific, written prior permission. This software is supplied as
- * is without expressed or implied warranties of any kind.
- *
- * ITD Research Systems
- * University of Michigan
- * 535 W. William Street
- * Ann Arbor, Michigan
- * +1-313-936-2652
- * netatalk@terminator.cc.umich.edu
- */
-
- #include <Memory.h>
- #include <files.h>
- #include <dialogs.h>
- #include <appletalk.h>
- #include <packages.h>
- #include <resources.h>
- #include <script.h>
- #include <errors.h>
- #include <ctype.h>
- #include <string.h>
- #include <quickdraw.h>
- #include <toolutils.h>
- #include <cursorctl.h>
-
- /*
- * MIT Kerberos and DES stuff
- */
- #include <des.h>
- #include <krb.h>
- #include <conf.h>
- #include <prot.h>
-
- #include "uam.h"
-
- /*
- * function prototypes
- */
- OSErr uam_open( Str255 name, Str255 zone );
- OSErr uam_close( void );
- OSErr uam_pwd_dialog( StringHandle name, char *passwd );
- OSErr uam_login( AddrBlock addr, short xrefnum, short retry, Ptr attn, Str255 name, char *passwd,
- short *srefnum, Ptr *scb );
-
- extern char afp_server[];
- extern char afp_zone[];
- Handle afp_iconhdl;
- Boolean afp_dosetpw;
- DialogPtr passwd_dlp;
- acurHandle acur_hdl;
-
- pascal OSErr
- uam_dispatch( opcode, new_A5p, addr, xrefnum, retry, attn, name, passwd, srefnum, scb )
- long opcode;
- long *new_A5p;
- AddrBlock addr;
- short xrefnum, retry, *srefnum;
- Ptr attn, *scb;
- Str255 name;
- char *passwd;
- /*
- * "opcode" is 1 for uam_open, 2 for uam_close, 3 for uam_pwd_dialog, 4 for uam_login
- * "new_A5p" is set if opcode is "uam_open"
- * the remainder of the above paramaters are correct for uam_login
- * for uam_open, "attn" above is actually "name" and "name" above is actually "zone"
- * for uam_pwd_dialog, "name" and "passwd" are as above
- * for uam_close, none of the parameters are used
- */
- {
- Ptr globalmem;
- long old_A5;
- OSErr rc;
-
- if ( opcode == OP_UAM_OPEN ) {
- /* DebugStr( "\puam initial open" ); /* */
- /*
- * initialize area off A5 for globals
- */
- if (( globalmem = NewPtr( A5Size())) == NULL ) {
- return( -1 );
- }
- mysetup_A5( globalmem, new_A5p );
- }
-
- old_A5 = SetA5( *new_A5p );
-
- switch( opcode ) {
- case OP_UAM_OPEN:
- /* DebugStr( "\puam_open" ); /* */
- mysetup_QD( old_A5 );
- rc = uam_open( (Str255)attn, (Str255)name );
- break;
- case OP_UAM_CLOSE:
- /* DebugStr( "\puam_close" ); /* */
- rc = uam_close();
- break;
- case OP_UAM_PWDDLOG:
- /* DebugStr( "\puam_pwdialog" ); /* */
- name[ 0 ] = 0;
- rc = uam_pwd_dialog( (char **)name, passwd );
- break;
- case OP_UAM_LOGIN:
- /* DebugStr( "\puam_login" ); /* */
- rc = uam_login( addr, xrefnum, retry, attn, name, passwd,
- srefnum, scb );
- break;
- default:
- rc = -1;
- }
- SetA5( old_A5 );
-
- if ( opcode == OP_UAM_CLOSE ) {
- /* DebugStr( "\puam final close" ); /* */
- globalmem = (Ptr) (*new_A5p - A5Size() + 32);
- DisposPtr( globalmem );
- }
-
- return( rc );
- }
-
-
- OSErr
- uam_open( name, zone )
- Str255 name, zone;
- {
- AddrBlock addr;
- Handle iconhdl;
- short iorefnum;
-
- /*
- * save name and zone of server in global space
- * (for mutual verification of authentication)
- */
- BlockMove( name, afp_server, *name + 1 );
- afp_server[ name[ 0 ] + 1 ] = '\0';
- BlockMove( zone, afp_zone, *zone + 1 );
- afp_zone[ zone[ 0 ] + 1 ] = '\0';
-
- /*
- * get icon from server via ASP status call
- */
- if ( OpenXPP( &iorefnum ) != noErr ) {
- doalert( ALRT_LOCALERR );
- return( -1 );
- }
-
- if ( lookup_address( afp_server, NBPTYPE_AFP, afp_zone , &addr ) != 0 ) {
- doalert( ALRT_REMOTEERR );
- return( -1 );
- }
- if ( get_server_status( iorefnum, addr, &afp_iconhdl, &afp_dosetpw ) != 0 ) {
- return( -1 );
- }
-
- /*
- * load acur (spinning watch cursor) resource
- */
- if (( acur_hdl = (acurHandle)Get1Resource( 'acur', ACUR_WATCH )) == NULL ) {
- doalert( ALRT_LOCALERR );
- return( -1 );
- }
- HLock( (Handle)acur_hdl );
- InitCursorCtl( acur_hdl );
-
- return( noErr );
- }
-
-
- OSErr
- uam_close( newA5 )
- {
- if ( afp_iconhdl != NULL ) {
- DisposHandle( afp_iconhdl );
- }
-
- HUnlock( (Handle)acur_hdl );
- ReleaseResource( (Handle)acur_hdl );
- return( noErr );
- }
-
- OSErr
- uam_pwd_dialog( name, passwd )
- char *name; /* P-string */
- char *passwd; /* C-string */
- {
- InitCursor();
- ParamText( NULL, afp_server, NULL, NULL );
- passwd_dlp = passwddialog( name, passwd, afp_iconhdl, UAM_PASSWD_DLOG,
- true, 0, afp_dosetpw );
-
- if ( passwd_dlp == NULL ) {
- bzero( passwd, MAXPASSWDLEN );
- return( -1 );
- }
- return( 0 );
- }
-
-
- OSErr
- uam_login( addr, xrefnum, retry, attn, name, passwd, srefnum, scb )
- AddrBlock addr;
- short xrefnum, retry, *srefnum;
- Ptr attn, *scb;
- char *name; /* P-string */
- char *passwd;
- {
- AFPLoginPrm alp;
- unsigned char logoutcmd = afpLogout;
- Handle hdl;
- short oresfile;
- des_cblock sesskey;
-
- oresfile = CurResFile();
- if (( hdl = GetResource( 'uamn', 0 )) == NULL ) {
- return( -1 );
- }
- UseResFile( HomeResFile( hdl ));
-
- for (;;) {
- bzero( &alp, sizeof( AFPLoginPrm ));
- alp.ioRefNum = xrefnum;
- alp.aspTimeout = retry;
- alp.afpAddrBlock = addr;
- alp.afpAttnRoutine = attn;
- *scb = alp.afpSCBPtr = NewPtrSysClear( scbMemSize );
-
- if ( dologin( true, true, &alp, name, passwd, srefnum, sesskey ) == 0 ) {
- break; /* success! */
- }
-
- /*
- * An error occurred during the login process.
- * Send a Logout command to the server.
- */
- alp.cbPtr = &logoutcmd;
- alp.cbSize = 1;
- alp.rbSize = 0;
- alp.rbPtr = NULL;
- alp.ioCompletion = NULL;
- if ( AFPCommand( (XPPParmBlkPtr)&alp, true ) == noErr ) {
- wait_for_completion( (XPPParmBlkPtr)&alp );
- }
- DisposPtr( *scb );
-
- /*
- * perform password dialog again (in case user just made a typo)
- */
- DisposDialog( passwd_dlp );
- if ( uam_pwd_dialog( name, passwd ) != 0 ) {
- UseResFile( oresfile );
- ReleaseResource( hdl );
- return( -1 );
- }
- }
-
- /*
- * successful login....
- */
- DisposDialog( passwd_dlp );
- UseResFile( oresfile );
- ReleaseResource( hdl );
- return( noErr );
- }